import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import*


testCase = "DBshop010_处理退货退款"

# 登录后台
firefox=openBrowser(urlAdmin)
#调用自定义函数进行后台的登录
DBshopLoginAdmin(firefox)
#调用后台的菜单操作函数
DBshopEnterMenu2(firefox,'销售管理','退货管理')
time.sleep(1)
#读取odrder1.txt文件中的订单编号
orderid=readFile(get_pro_rootpath()+'\public\order1.txt')
# 输入订单号进行搜索
firefox.find_element_by_name("order_sn").send_keys(orderid)
firefox.find_element_by_xpath('//button[contains(text(),"搜索")]').click()
# 处理退货
firefox.find_element_by_link_text("处理退货").click()
firefox.find_element_by_xpath('//select[@id="refund_state"]/option[1]')
firefox.find_element_by_id("refund_price").clear()
firefox.find_element_by_id("refund_price").send_keys("2199")
firefox.find_element_by_id("re_refund_info").send_keys("同意")
firefox.find_element_by_xpath('//button').click()

# 登录前台进行退货查询
firefox.get(url)
#调用自定义函数进行登录
DBshopLogin(firefox,userName,password)
firefox.find_element_by_link_text("我的订单").click()
# 定位退货申请
firefox.find_element_by_link_text("退货申请").click()
firefox.find_element_by_name("search_content").send_keys(orderid)
firefox.find_element_by_xpath('//button[text()="搜索"]').click()

# 断言
try:
    if firefox.find_element_by_xpath("//table/tbody/tr/td[4]").text=="退款成功":
       writeLog("%s 测试成功" % testCase)
except:
    writeLog("%s 测试不通过" % testCase)
    getPhoto(firefox)
firefox.quit()